home *** CD-ROM | disk | FTP | other *** search
/ Clickx 63 / Clickx 63.iso / software / multimedia / mirov204 / Miro_Installer.exe / xulrunner / chrome / toolkit.jar / content / global / charsetOverlay.js < prev    next >
Encoding:
Text File  |  2006-09-19  |  8.5 KB  |  275 lines

  1. function MultiplexHandler(event)
  2. {
  3.     var node = event.target;
  4.     var name = node.getAttribute('name');
  5.  
  6.     if (name == 'detectorGroup') {
  7.         SetForcedDetector(true);
  8.         SelectDetector(event, false);
  9.     } else if (name == 'charsetGroup') {
  10.         var charset = node.getAttribute('id');
  11.         charset = charset.substring('charset.'.length, charset.length)
  12.         SetForcedCharset(charset);
  13.     } else if (name == 'charsetCustomize') {
  14.         //do nothing - please remove this else statement, once the charset prefs moves to the pref window
  15.     } else {
  16.         SetForcedCharset(node.getAttribute('id'));
  17.     }
  18. }
  19.  
  20. function MailMultiplexHandler(event)
  21. {
  22.     var node = event.target;
  23.     var name = node.getAttribute('name');
  24.  
  25.     if (name == 'detectorGroup') {
  26.         SelectDetector(event, true);
  27.     } else if (name == 'charsetGroup') {
  28.         var charset = node.getAttribute('id');
  29.         charset = charset.substring('charset.'.length, charset.length)
  30.         MessengerSetForcedCharacterSet(charset);
  31.     } else if (name == 'charsetCustomize') {
  32.         //do nothing - please remove this else statement, once the charset prefs moves to the pref window
  33.     } else {
  34.         MessengerSetForcedCharacterSet(node.getAttribute('id'));
  35.     }
  36. }
  37.  
  38. function ComposerMultiplexHandler(event)
  39. {
  40.     var node = event.target;
  41.     var name = node.getAttribute('name');
  42.  
  43.     if (name == 'detectorGroup') {
  44.         ComposerSelectDetector(event, true);
  45.     } else if (name == 'charsetGroup') {
  46.         var charset = node.getAttribute('id');
  47.         charset = charset.substring('charset.'.length, charset.length)
  48.         EditorSetDocumentCharacterSet(charset);
  49.     } else if (name == 'charsetCustomize') {
  50.         //do nothing - please remove this else statement, once the charset prefs moves to the pref window
  51.     } else {
  52.         SetForcedEditorCharset(node.getAttribute('id'));
  53.     }
  54. }
  55.  
  56. function SelectDetector(event, doReload)
  57. {
  58.     dump("Charset Detector menu item pressed: " + event.target.getAttribute('id') + "\n");
  59.  
  60.     var uri =  event.target.getAttribute("id");
  61.     var prefvalue = uri.substring('chardet.'.length, uri.length);
  62.     if ("off" == prefvalue) { // "off" is special value to turn off the detectors
  63.         prefvalue = "";
  64.     }
  65.  
  66.     try {
  67.         var pref = Components.classes["@mozilla.org/preferences-service;1"]
  68.                              .getService(Components.interfaces.nsIPrefBranch);
  69.         var str =  Components.classes["@mozilla.org/supports-string;1"]
  70.                              .createInstance(Components.interfaces.nsISupportsString);
  71.  
  72.         str.data = prefvalue;
  73.         pref.setComplexValue("intl.charset.detector",
  74.                              Components.interfaces.nsISupportsString, str);
  75.         if (doReload) window.content.location.reload();
  76.     }
  77.     catch (ex) {
  78.         dump("Failed to set the intl.charset.detector preference.\n");
  79.     }
  80. }
  81.  
  82. function ComposerSelectDetector(event)
  83. {
  84.     //dump("Charset Detector menu item pressed: " + event.target.getAttribute('id') + "\n");
  85.  
  86.     var uri =  event.target.getAttribute("id");
  87.     var prefvalue = uri.substring('chardet.'.length, uri.length);
  88.     if ("off" == prefvalue) { // "off" is special value to turn off the detectors
  89.         prefvalue = "";
  90.     }
  91.  
  92.     try {
  93.         var pref = Components.classes["@mozilla.org/preferences-service;1"]
  94.                              .getService(Components.interfaces.nsIPrefBranch);
  95.         var str =  Components.classes["@mozilla.org/supports-string;1"]
  96.                              .createInstance(Components.interfaces.nsISupportsString);
  97.  
  98.         str.data = prefvalue;
  99.         pref.setComplexValue("intl.charset.detector",
  100.                              Components.interfaces.nsISupportsString, str);
  101.         EditorLoadUrl(GetDocumentUrl());    
  102.     }
  103.     catch (ex) {
  104.         dump("Failed to set the intl.charset.detector preference.\n");
  105.     }
  106. }
  107.  
  108. function SetForcedDetector(doReload)
  109. {
  110.     BrowserSetForcedDetector(doReload);
  111. }
  112.  
  113. function SetForcedCharset(charset)
  114. {
  115.     BrowserSetForcedCharacterSet(charset);
  116. }
  117.  
  118. var gPrevCharset = null;
  119. function UpdateCurrentCharset()
  120. {
  121.     var menuitem = null;
  122.  
  123.     // exctract the charset from DOM
  124.     var wnd = document.commandDispatcher.focusedWindow;
  125.     if ((window == wnd) || (wnd == null)) wnd = window.content;
  126.     menuitem = document.getElementById('charset.' + wnd.document.characterSet);
  127.  
  128.     if (menuitem) {
  129.         // uncheck previously checked item to workaround Mac checkmark problem
  130.         // bug 98625
  131.         if (gPrevCharset) {
  132.             var pref_item = document.getElementById('charset.' + gPrevCharset);
  133.             if (pref_item)
  134.               pref_item.setAttribute('checked', 'false');
  135.         }
  136.         menuitem.setAttribute('checked', 'true');
  137.     }
  138. }
  139.  
  140. function UpdateCurrentMailCharset()
  141. {
  142.     var charset = msgWindow.mailCharacterSet;
  143.     var menuitem = document.getElementById('charset.' + charset);
  144.  
  145.     if (menuitem) {
  146.         menuitem.setAttribute('checked', 'true');
  147.     }
  148. }
  149.  
  150. function UpdateCharsetDetector()
  151. {
  152.     var prefvalue;
  153.  
  154.     try {
  155.         var pref = Components.classes["@mozilla.org/preferences-service;1"]
  156.                              .getService(Components.interfaces.nsIPrefBranch);
  157.         prefvalue = pref.getComplexValue("intl.charset.detector",
  158.                                          Components.interfaces.nsIPrefLocalizedString).data;
  159.     }
  160.     catch (ex) {
  161.         prefvalue = "";
  162.     }
  163.  
  164.     if (prefvalue == "") prefvalue = "off";
  165.     dump("intl.charset.detector = "+ prefvalue + "\n");
  166.  
  167.     prefvalue = 'chardet.' + prefvalue;
  168.     var menuitem = document.getElementById(prefvalue);
  169.  
  170.     if (menuitem) {
  171.         menuitem.setAttribute('checked', 'true');
  172.     }
  173. }
  174.  
  175. function UpdateMenus(event)
  176. {
  177.     // use setTimeout workaround to delay checkmark the menu
  178.     // when onmenucomplete is ready then use it instead of oncreate
  179.     // see bug 78290 for the detail
  180.     UpdateCurrentCharset();
  181.     setTimeout(UpdateCurrentCharset, 0);
  182.     UpdateCharsetDetector();
  183.     setTimeout(UpdateCharsetDetector, 0);
  184. }
  185.  
  186. function CreateMenu(node)
  187. {
  188.   var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
  189.   observerService.notifyObservers(null, "charsetmenu-selected", node);
  190. }
  191.  
  192. function UpdateMailMenus(event)
  193. {
  194.     // use setTimeout workaround to delay checkmark the menu
  195.     // when onmenucomplete is ready then use it instead of oncreate
  196.     // see bug 78290 for the detail
  197.     UpdateCurrentMailCharset();
  198.     setTimeout(UpdateCurrentMailCharset, 0);
  199.     UpdateCharsetDetector();
  200.     setTimeout(UpdateCharsetDetector, 0);
  201. }
  202.  
  203. var gCharsetMenu = Components.classes['@mozilla.org/rdf/datasource;1?name=charset-menu'].getService().QueryInterface(Components.interfaces.nsICurrentCharsetListener);
  204. var gLastBrowserCharset = null;
  205.  
  206. function charsetLoadListener (event)
  207. {
  208.     var charset = window.content.document.characterSet;
  209.  
  210.     if (charset.length > 0 && (charset != gLastBrowserCharset)) {
  211.         gCharsetMenu.SetCurrentCharset(charset);
  212.         gPrevCharset = gLastBrowserCharset;
  213.         gLastBrowserCharset = charset;
  214.     }
  215. }
  216.  
  217.  
  218. function composercharsetLoadListener (event)
  219. {
  220.     var charset = window.content.document.characterSet;
  221.  
  222.  
  223.     if (charset.length > 0 ) {
  224.        gCharsetMenu.SetCurrentComposerCharset(charset);
  225.     }
  226.  }
  227.  
  228. function SetForcedEditorCharset(charset)
  229. {
  230.     if (charset.length > 0 ) {
  231.        gCharsetMenu.SetCurrentComposerCharset(charset);
  232.     }
  233.     EditorSetDocumentCharacterSet(charset);
  234. }
  235.  
  236.  
  237. var gLastMailCharset = null;
  238.  
  239. function mailCharsetLoadListener (event)
  240. {
  241.     if (msgWindow) {
  242.         var charset = msgWindow.mailCharacterSet;
  243.         if (charset.length > 0 && (charset != gLastMailCharset)) {
  244.             gCharsetMenu.SetCurrentMailCharset(charset);
  245.             gLastMailCharset = charset;
  246.         }
  247.     }
  248. }
  249.  
  250. var wintype = document.documentElement.getAttribute('windowtype');
  251. if (window && (wintype == "navigator:browser"))
  252. {
  253.     var contentArea = window.document.getElementById("appcontent");
  254.     if (contentArea)
  255.         contentArea.addEventListener("pageshow", charsetLoadListener, true);
  256. }
  257. else
  258. {
  259.     var arrayOfStrings = wintype.split(":");
  260.     if (window && arrayOfStrings[0] == "mail") 
  261.     {
  262.         var messageContent = window.document.getElementById("messagepane");
  263.         if (messageContent)
  264.             messageContent.addEventListener("pageshow", mailCharsetLoadListener, true);
  265.     }
  266.     else
  267.     if (window && arrayOfStrings[0] == "composer") 
  268.     {
  269.         contentArea = window.document.getElementById("appcontent");
  270.         if (contentArea)
  271.             contentArea.addEventListener("pageshow", composercharsetLoadListener, true);
  272.     }
  273.  
  274. }
  275.